package dev.werillib.android

import android.app.Activity
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat

object PermissionUtil {
    fun checkSelfPermission(context: Context, permissions: Array<String>): Boolean {
        var bReturn = true
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {// 检查该权限是否已经获取
            for (i in permissions.indices) {
                val p = ContextCompat.checkSelfPermission(context, permissions[i])
                if (p != PackageManager.PERMISSION_GRANTED) {
                    bReturn = false
                    break
                }
            }
        }
        return bReturn
    }

    fun requestPermission(activity: Activity, permissions: Array<String>, requestCode: Int) {
        ActivityCompat.requestPermissions(activity, permissions, requestCode)
    }
}
